#!/bin/bash
yum_config(){
    rm -rf /etc/yum.repos.d/*
    mkdir -p /etc/yum.repos.d/
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    yum_clean "系统源配置"
    echo '[centos-openstack-queens]
name=CentOS-7 - OpenStack queens
baseurl=http://mirrors.tuna.tsinghua.edu.cn/$contentdir/$releasever/cloud/$basearch/openstack-queens/
gpgcheck=0
enabled=1' > /etc/yum.repos.d/tsinghua-OpenStack-queens.repo
    yum_clean "清华OpenStack-queens源配置"
    echo '[centos-qemu-ev]
name=CentOS-$releasever - QEMU EV
#mirrorlist=http://mirrors.tuna.tsinghua.edu.cn/?release=$releasever&arch=$basearch&repo=virt-kvm-common
baseurl=http://mirrors.tuna.tsinghua.edu.cn/$contentdir/$releasever/virt/$basearch/kvm-common/
gpgcheck=0
enabled=1' > /etc/yum.repos.d/tsinghua-QEMU-EV.repo
    yum_clean "清华qemu-ev源配置"
    curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    yum_clean "eprl源配置"
#     echo '[mongodb-org] 
# name = MongoDB Repository
# baseurl = https://mirrors.aliyun.com/mongodb/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
# gpgcheck = 1 
# enabled = 1 
# gpgkey = https：// www.mongodb.org/static/pgp/server-3.6.asc' > /etc/yum.repos.d/mongod.repo
#     echo '[centos-storage-debuginfo]
# name=CentOS-$releasever - Storage SIG - debuginfo
# baseurl=http://debuginfo.centos.org/$contentdir/$releasever/storage/$basearch/
# gpgcheck=0
# enabled=1' > /etc/yum.repos.d/tsinghua-storage.repo
#     yum_clean "Storage源配置"
    # if [[ `yum repolist | wc -l` -eq '10' ]];then
    #     print_red_z_green_z_info "所有源配置" "成功"
    # fi
    print_red_z_green_z_info "正在进行" "源索引创建"
    print_red_z_green_z_info "当前脚本进程PID---->>>" "$$"
    # mv  /yum_bak/* /etc/yum.repos.d/
    yum_clean "所有源配置"
    print_red_z_green_z_info "正在进行-->>" "源索引重建,请耐心等待"
    yum makecache
    chek_status "$?" "索引更新"
    print_red_z_green_z_info "正在进行-->>" "软件更新，请耐心等待"
    yum upgrade
    chek_status "$?" "软件升级"
}